﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using CSCV.Group8.BlogRollWebPart.Helper;

namespace CSCV.Group8.BlogRollWebPart.Model
{
    /// <summary>
    /// Represent the comment of blog
    /// </summary>
    public class BRComment
    {
        #region prop
        /// <summary>
        /// Post ID of the comment
        /// </summary>
        public string PostID { get; set; }

        /// <summary>
        /// The body of the comment
        /// </summary>
        public string Contents { get; set; }

        /// <summary>
        /// Datetime when comment created
        /// </summary>
        public DateTime DateCreated { get; set; }

        /// <summary>
        /// Author of the comment
        /// </summary>
        public string Author { get; set; }

        /// <summary>
        /// The Post title follow this form: PostID + ";#" + Title of the post
        /// </summary>
        public string PostTitle { get; set; }

        /// <summary>
        /// Title of the comment
        /// </summary>
        public string Title { get; set; }
        #endregion

        #region ctor

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="spli">SPListItem represent the comment item</param>
        /// <param name="postId">the post ID to be commenting</param>
        public BRComment(SPListItem spli, string postId)
        {
            try
            {
                string StrPostID = spli[HelperConst.POST_ID_TAG].ToString();
                int Index = StrPostID.IndexOf(';'); //index
                this.PostID = StrPostID;
                this.Title = spli.GetFormattedValue(HelperConst.TITLE_TAG);
                this.Contents = HelperLib.ReplaceNewLine(spli.GetFormattedValue(HelperConst.COMMENT_CONTENT_TAG)); ;
                this.DateCreated = (DateTime)spli[HelperConst.DATE_MODIFIED_TAG];
                this.Author = spli.GetFormattedValue(HelperConst.AUTHOR_TAG);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}
